<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/include/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Basic Development Framework</title>
<d:script id="jquery,jquery-cookie,om-ui" />
<d:css id="om-ui" />
<d:css path="static/style/common.css"/>
<script type="text/javascript">
$(document).ready(function() {
	(function(win){
		win.saveData = function(){//保存数据
			var currentNode = treeDept.getSelected();
			$("#formDept").omAjaxSubmit({  
				dataType:"json",
				success:function(data){
					if(data.success){
						$.omMessageTip.show({
							timeout:3000,
							title:"提示",
							content:"操作成功！"
						});
						treeDept.modify(currentNode,data.data);
					} else {
						$.omMessageTip.show({
							timeout:3000,
							title:"失败",
							content:data.msg
						});
					}
				}
			});
		}
		win.addSubDept=function(){
			var currentNode = treeDept.getSelected();
			var nodeData = currentNode && currentNode.data || {};
			var childNode = {
					text:"<新部门>",
					pid:nodeData.id,
					data:{name:"<新部门>",parent:{id:nodeData.id}}
			}
			treeDept.insert(childNode,currentNode);
			treeDept.select(childNode);
			$(":input[name]",$("#formDept")).each(function(){
				$(this).val(childNode.data[$(this).attr("name")]);
			});
			$(":input[name='parent.id']",$("#formDept")).val(nodeData.id);
			$(":input[name='parent.name']",$("#formDept")).val(nodeData.name);
		}
		win.treeSelectEvent=function(node){
			var nodeData=node.data;
			$(":input[name]",$("#formDept")).each(function(){
				$(this).val(nodeData[$(this).attr("name")]);
			});
			$(":input[name='parent.id']",$("#formDept")).val(nodeData.parent&&nodeData.parent.id || "");
			$(":input[name='parent.name']",$("#formDept")).val(nodeData.parent&&nodeData.parent.name || "");
		}
	})(window);
	
	//对页面中的组件进行初始化
	initUI();
});
</script>
</head>
<body class="ui-border-layout">
	<div id="north-panel" class="ui-border-layout-panel" region="north" header="false"
		height="32">
		<div class="ui-buttonbar">
			<button id="buttonAddSubDept" click="function(){addSubDept();}" class="ui-button" label="新增子部门"></button>
			<button id="buttonSave" click="function(){saveData();}" class="ui-button" label="  保存 "></button>
		</div>
	</div>
	<div id="west-panel" class="ui-border-layout-panel" label="部门列表"
		width="180" region="west" resizable="true" collapsible="true">
		<div id="treeDept" class="ui-tree" dataSource="${ctx }/system/dept/treeData" simpleDataModel="true" onSelect="function(rowData){treeSelectEvent(rowData);}"></div>
	</div>
	<div id="center-panel" class="ui-border-layout-panel" region="center" header="false">
		<!-- 主面板 -->
		<form id="formDept" method="POST" action="${ctx }/system/dept/ajaxSave">
			<input type="hidden" name="id">
			<input type="hidden" name="parent.id">
		<table>
			<tr>
				<th>部门名称:</th>
				<td><input type="text" name="name" /></td>
			</tr>
			<tr>
				<th>上级部门:</th>
				<td><input type="text" disabled="disabled" name="parent.name"/></td>
			</tr>
			<tr>
				<th>部门描述:</th>
				<td><textarea name="remark" style="width:200px;height:60px"></textarea></td>
			</tr>
		</table>
		</form>
	</div>
</body>
</html>